
      <!--main content start-->
      <section id="main-content">
          <section class="wrapper">
            <h3><i class="fa fa-angle-right"></i> 分类添加</h3>
            
            <!-- BASIC FORM ELELEMNTS -->
            <div class="row mt">
                <div class="col-lg-12">
                  <div class="form-panel">


                      <!-- 新闻表单开始-->  
                      <form class="form-horizontal style-form" action="" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                              <label class="col-sm-2 col-sm-2 control-label">分类名称</label>
                              <div class="col-sm-10">
                                  <input type="text" name="name" class="form-control" placeholder="请输入标题">
                              </div>
                          </div>
                      <div class="form-group">
                            <label class="col-sm-2 control-label">分类归属</label>
                          <div class="col-sm-2 list">
                            <select class="form-control select_cate" name="pid">
                              <option value="0">顶级分类</option>
                              <?php foreach($cate as $v){?>
                              <option value="<?php echo $v['id']?>"><?php echo $v['name']?></option>
                              <?php }?>
                            </select>
                          </div>

                      </div>
                                                

                          <div class="form-group">
                          <div class="col-sm-2 col-sm-2 control-label">
                            <button type="submit" class="form-control">提交</button>
                          
                          </div>
                          </div>

                      </form>
                      <!-- 表单结束-->   
                  </div>
                </div><!-- col-lg-12-->         
            </div><!-- /row -->

     </section><! --/wrapper -->
       </section><!-- /MAIN CONTENT -->

       <!--main content end-->
      <script src="resource/admin/assets/js/jquery-2.1.4.min.js"></script>
       <script type="text/javascript">
          $(function(){
            $('.list').on('change','select',function(){

                //删除当前操作之后的所有select标签
                $(this).nextAll().remove();
                //选中的是上一级则中止程序执行
                  // alert($(this).find('option:selected').text());
                  console.log($(this));
                  if($(this).get(0).selectedIndex==0){

                    return false;
                  }
                  
                //选中项id值
                var id = $(this).val();

                //通过ajax获取选中项的子级数据
                $.ajax({
                type:'get',
                url:'index.php?c=cate&a=add&admin=1&id='+id,
                dataType:'json',
                success:function(json){
                            var html='';
                            html+='<select class="form-control select_cate" name="pid">';
                              html+='<option value="'+id+'">上一级分类</option>';

                              for(i in json){

                                  html+='<option value="'+json[i].id+'">'+json[i].name+'</option>';
                              }
                              
                            html+='</select>';

                            //将新的下拉列表追加在原来的下拉列表后面
                            $('.list').append(html);

                  }

                })
            })
          })
       </script>